package presentation.view_helpers;

import static org.junit.Assert.assertTrue;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import persistence.DAOFactoryJdbcTestImpl;
import persistence.Subscription;
import business.BusinessObjectAssembler;
import business.SubscriptionLogic;
import business.SubscriptionLogicTestImpl;
import business.exception.BusinessException;

public class SubscriptionOverviewTest {
	private SubscriptionLogic subscriptionLogic;
	private SubscriptionBean subscriptionBean;
	
	@Before
	public void setUp() {
		subscriptionLogic = new SubscriptionLogicTestImpl();
		BusinessObjectAssembler.setDaoFactory(new DAOFactoryJdbcTestImpl());
		subscriptionBean = new SubscriptionBean();
		subscriptionBean.setSubscriptionLogic(subscriptionLogic);
	}

	@Test
	public void testGetStartLetters() throws BusinessException{
		//inject a subscription logic test impl using a DAO test impl
		System.out.println(subscriptionBean);
		//insert two new subscriptions
		Subscription sub1 = subscriptionLogic.getAllSubscriptions().get(0);
		subscriptionBean.setCurrentSubscription(sub1);
		subscriptionBean.createNewSubscription();
		
		
		List<Character> startLetters = subscriptionBean.getStartLetters();
		assertTrue(startLetters.get(0).equals("A"));
		assertTrue(startLetters.get(1).equals("B"));
		assertTrue(startLetters.size()==2);		
	}
	
	@Test(expected=IllegalArgumentException.class)
	public void wrongDateTest() {
		//setting invalid Date
		GregorianCalendar cal = (GregorianCalendar)Calendar.getInstance();		
		cal.setLenient(false);
		cal.set(Calendar.DAY_OF_MONTH, 34);		
	}
}
